package com.example.beat_x3.Adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.beat_x3.R;

import Entity.Inf;
import Entity.Replys;

public class FeedbackAdapter extends RecyclerView.Adapter<FeedbackAdapter.Holder> {
    public Replys res;
    int size = 0;

    @NonNull
    @Override
    public FeedbackAdapter.Holder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new FeedbackAdapter.Holder(LayoutInflater.from(Inf.context).inflate(R.layout.item_feedback, parent, false));
    }

    @Override
    public void onBindViewHolder(@NonNull FeedbackAdapter.Holder holder, int position) {
        holder.bind(position);
    }
    public void refreshOne() {
        notifyItemRangeChanged(size, res.complaints.size());
        size = res.complaints.size();
    }

    @Override
    public int getItemCount() {
        if (res == null) return 0;
        return res.complaints.size();
    }

    class Holder extends RecyclerView.ViewHolder {

        TextView complaint, reply;

        public Holder(@NonNull View itemView) {
            super(itemView);
            this.complaint = itemView.findViewById(R.id.user_content);
            this.reply = itemView.findViewById(R.id.admin_content);
        }

        void bind(int position) {
            complaint.setText(res.complaints.get(position));
            reply.setText(res.replys.get(position));
        }
    }
}
